package net.zjitc.doubao_community_backed.service.impl;/**
 * @Author 董熠涛
 * @Date 2025/6/20  9:23
 */

/**
 * @Author:董熠涛
 * @ 2025/6/209:23
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.zjitc.doubao_community_backed.mapper.BmsTagMapper;
import net.zjitc.doubao_community_backed.model.entity.BmsTag;
import net.zjitc.doubao_community_backed.service.IBmsPostService;
import net.zjitc.doubao_community_backed.service.IBmsTagService;
import net.zjitc.doubao_community_backed.service.IBmsTopicTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IBmsTagServiceImpl extends ServiceImpl<BmsTagMapper, BmsTag> implements IBmsTagService {

    @Autowired
    private IBmsTopicTagService iBmsTopicTagService;

    @Autowired
    private IBmsPostService iBmsPostService;


    @Override
    public List<BmsTag> insertTags(List<String> tagNames) {
        List<BmsTag> tagList = new ArrayList<>();
        for (String tagName : tagNames) {
            BmsTag tag = this.baseMapper.selectOne(new LambdaQueryWrapper<BmsTag>().eq(BmsTag::getName, tagName));
            if (tag == null) {
                tag = BmsTag.builder().name(tagName).build();
                this.baseMapper.insert(tag);
            } else {
                tag.setTopicCount(tag.getTopicCount() + 1);
                this.baseMapper.updateById(tag);
            }
            tagList.add(tag);
        }
        return tagList;
    }



}
